package com.cloud.pora.mrm.web;

import java.util.List;

import javax.persistence.EntityManager;

import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Begin;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Logger;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Out;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.datamodel.DataModel;
import org.jboss.seam.annotations.datamodel.DataModelSelection;
import org.jboss.seam.log.Log;

import com.cloud.pora.mrm.model.MeetingRoom;

@Scope(ScopeType.CONVERSATION)
@Name("meetingRoomListAction")
public class MeetingRoomListAction {
    @Logger
    private Log log;

    @In
    EntityManager entityManager;

    @DataModel("meetingRooms")
    private List<MeetingRoom> meetingRooms;

    @DataModelSelection("meetingRooms")
    MeetingRoom selectedMeetingRoom;

    @Out(required = false)
    MeetingRoom meetingRoom;

    private boolean initFlag = true;

    public boolean isInitFlag() {
        return initFlag;
    }

    public void setInitFlag(boolean initFlag) {
        this.initFlag = initFlag;
    }

    public String page() {
        initFlag = false;
        this.meetingRooms = entityManager.createQuery(
                "select t from MeetingRoom t").getResultList();
        return "success";
    }

//    public List<MeetingRoom> getMeetingRooms() {
//        page();
//        return meetingRooms;
//    }

    public String showDetail() {
        meetingRoom = selectedMeetingRoom;
        return "meetingRoomDetail";
    }

    public String edit() {
        meetingRoom = selectedMeetingRoom;
        return "edit";
    }

}
